#ifndef _NTPPACKET_HPP_
#define _NTPPACKET_HPP_

#include "jhdefs.hpp"
#include "types.hpp"
#include "stdlib/timestamp.hpp"
using JHCPP::stdlib::CTimeStamp;

NET_NAMESPACE_BEGIN

class CNTPPacket
{
public:
	CNTPPacket();
	CNTPPacket(UInt8 *packet);
	~CNTPPacket();

	void packet(UInt8 *packet) const;
	void setPacket(UInt8 *packet);

	Int8 leapIndicator() const;
	Int8 version() const;
	Int8 mode() const;
	Int8 stratum() const;
	Int8 pool() const;
	Int8 precision() const;

	Int32 rootDelay() const;
	Int32 rootDispersion() const;
	Int32 referenceId() const;

	Int64 referenceTimestamp() const;
	Int64 originateTimestamp() const;
	Int64 receiveTimestamp() const;
	Int64 transmitTimestamp() const;

	CTimeStamp referenceTime() const;
	CTimeStamp originateTime() const;
	CTimeStamp receiveTime() const;
	CTimeStamp transmitTime() const;

private:
	CTimeStamp convertTime(Int64 tm) const;

	Int8 m_leapIndicator;
	Int8 m_version;
	Int8 m_mode;
	Int8 m_stratum;
	Int8 m_pool;
	Int8 m_precision;
	Int32 m_rootDelay;
	Int32 m_rootDispersion;
	Int32 m_referenceId;
	Int64 m_referenceTimestamp;
	Int64 m_originateTimestamp;
	Int64 m_receiveTimestamp;
	Int64 m_transmitTimestamp;
};


NET_NAMESPACE_END

#endif
